package com.test.frame

import com.app.web.user.UserAction
import com.test.BaseJerseyServiceTest
import org.glassfish.jersey.server.ResourceConfig
import org.junit.Test

import javax.ws.rs.client.Entity
import javax.ws.rs.core.Application

/**
 * rest full规范测试
 * Created by three on 14-7-30.
 * User： 王利平
 */
class RestFullTest extends BaseJerseyServiceTest {
    @Override
    protected Application configure(ResourceConfig rc) {
        rc.register(UserAction.class);
        return rc;
    }

    String restFullUrl = "/user/list";

    @Test
    void testGetWithSuccess() {
        def res = target(restFullUrl).request().get();
        assert res.getStatus() == 200;
        def inputStream = res.readEntity(InputStream.class);
        println(inputStream.readLines());
        inputStream.close();
    }

    @Test
    void testPostWithSuccess() {
        def res = target(restFullUrl).request().post(Entity.text("asdfsfdd"));
        assert res.getStatus() == 200;
    }

    @Test
    void testPutWithNotMethod() {
        def res = target(restFullUrl).request().put(Entity.text("asdfsfdd"));
        assert res.getStatus() == 405;
    }

    @Test
    void testDeleteWithWithNotMethod() {
        def res = target(restFullUrl).request().delete();
        assert res.getStatus() == 405;
    }
}
